<link rel="stylesheet" href="../../../js/terminal/xterm.css" />
<div id="terminal" style="width: 100%; height: 100%"></div>
<script src="../../../js/terminal/xterm.js" charset="utf-8"></script>
<script src="../../../js/terminal/terminal.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="../../js/common.js" charset="utf-8"></script>
<script>
	openTerminal({
		operate : 'connect',
		appId : localStorage.getItem('appId_' + parent.layui.$("#userName").val()),
		envId : parent.envId,
		replicaName : parent.replicaName,
		loginToken : getCookie('login_token')
	});
	function openTerminal(options) {
		var client = new WSSHClient();
		var term = new Terminal({
			rows : 29,
			cursorBlink : true, // 光标闪烁
			cursorStyle : "block", // 光标样式  null | 'block' | 'underline' | 'bar'
			scrollback : 800, //回滚
			tabStopWidth : 8, //制表宽度
			screenKeys : true
		});

		term.on('data', function(data) {
			//键盘输入时的回调函数
			client.sendClientData(data);
		});
		term.open(document.getElementById('terminal'));
		//在页面上显示连接中...
		//执行连接操作
		client.connect({
			onError : function(error) {
				//连接失败回调
				term.write('Error: ' + error + '\r\n');
			},
			onConnect : function() {
				//连接成功回调
				client.sendInitData(options);
			},
			onClose : function() {
				//连接关闭回调
				term.write("\rconnection closed");
			},
			onData : function(data) {
				//收到数据时回调
				term.write(data);
			}
		});
	}
</script>